package wangjg.android.wifiadmin;

import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

public class EggsActivity extends BasicActivity {
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.eggs);
    }
    
    public void onStart() {
    	super.onStart();
    	this.initEvent();
    	this.readWifiSetup();
    }
    
    private void initEvent(){
    	//Alarm
    	Button btn_cancelAlarm = (Button)findViewById(R.id.btn_cancelAlarm);
    	btn_cancelAlarm.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			BizModule.cancelAlarm(EggsActivity.this);
    		}
    	});
    	
    	Button btn_setupAlarm = (Button)findViewById(R.id.btn_setupAlarm);
    	btn_setupAlarm.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			BizModule.setAlarm(EggsActivity.this);
    		}
    	});
    	
    	//Receiver
    	Button btn_enableReceiver = (Button)findViewById(R.id.btn_enableReceiver);
    	btn_enableReceiver.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			BizModule.enableComponent(EggsActivity.this, StatusReceiver.class);
    		}
    	});
    	
    	Button btn_disableReceiver = (Button)findViewById(R.id.btn_disableReceiver);
    	btn_disableReceiver.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			BizModule.disableComponent(EggsActivity.this, StatusReceiver.class);
    		}
    	});
    	
    	//Service
    	Button btn_startService = (Button)findViewById(R.id.btn_startService);
    	btn_startService.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			
    		}
    	});
    	
    	Button btn_stopService = (Button)findViewById(R.id.btn_stopService);
    	btn_stopService.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			
    		}
    	});
    	
    	
    	Button btn_save_interval = (Button)findViewById(R.id.btn_save_interval);
    	btn_save_interval.setOnClickListener(new OnClickListener(){
    		public void onClick(View v) {
    			saveWifiSetup();
    		}
    	});
    }
    
    private void readWifiSetup(){
		SharedPreferences pref = this.getSharedPreferences();
		String alarm_interval = pref.getString("alarm_interval", null);

		EditText text_alarm_interval = (EditText)findViewById(R.id.text_alarm_interval);
		text_alarm_interval.setText(alarm_interval);
	}

	private void saveWifiSetup(){
		EditText text_alarm_interval = (EditText)findViewById(R.id.text_alarm_interval);
		
		String alarm_interval = text_alarm_interval.getText().toString();
		
		SharedPreferences pref = this.getSharedPreferences();
		Editor editor = pref.edit();
		editor.putString("alarm_interval", alarm_interval);
		editor.commit();
		
		new AlertDialog.Builder(this)
			.setMessage(R.string.save_success)
			.setPositiveButton(R.string.button_ok, null)
			.show();
    }
	
}
